package demo1;

import java.util.ArrayList;
import java.util.List;

class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;
     TreeNode() {}
     TreeNode(int val) { this.val = val; }
    TreeNode(int val, TreeNode left, TreeNode right) {
          this.val = val;
         this.left = left;
        this.right = right;
     }
 }

public class Test {
    List<Integer> list = new ArrayList<>();
    public static void main(String[] args) {

    }
    public List<Integer> preorderTraversal(TreeNode root) {
        pre(root);
        return list;
    }
    public void pre (TreeNode root) {
        if (root == null) {
            return;
        }
        list.add(root.val);
        preorderTraversal(root.left);
        preorderTraversal(root.right);
    }
    public static TreeNode createTree () {
        TreeNode treeNode1 = new TreeNode(1);
        TreeNode treeNode2 = new TreeNode(1);
        TreeNode treeNode3 = new TreeNode(1);
        treeNode1.right = treeNode2;
        treeNode2.left = treeNode3;
        return treeNode1;
    }
    // 获取叶子节点的个数
    int getLeafNodeCount(TreeNode root) {
        int count = 0;
        if (root == null) {
            return 0;
        }
        if (root.left == null && root.right == null) {
            return 1;
        }
        count += getLeafNodeCount(root.left);
        count += getLeafNodeCount(root.right);
        return count;
    }
}
